
#include "nane/FileArchiveSystem/FileArchiveSystem.h"
#include "nane/FileArchiveSystem/FileArchiveSystemImpl_.h"
#include "nane/FileArchiveSystem/FileArchiveImpl_.h"
#include "nane/core/assert.h"


namespace nane
{
    ////////////////////////////////////////////////////////////////////////////////////////////////
    FileArchiveSystem::FileArchiveSystem()
        : SubSystem<IFileArchiveSystem>( new Implementation() )
        , m( static_cast<Implementation*>(SubSystem<IFileArchiveSystem>::m) )
    {
        
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    FileArchiveSystem::~FileArchiveSystem()
    {
        Shutdown();
        delete m;
        m = NULL;
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    const char* FileArchiveSystem::GetFileType()
    {
        NANE_ASSERT_RV( m->interface != NULL, "FileArchiveSystem must be initialized", "" );
        return m->interface->GetFileType();
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    FileArchive FileArchiveSystem::CreateArchive( const InputSeekablePtr& _input )
    {
        NANE_ASSERT_RV( m->interface != NULL, "FileArchiveSystem must be initialized", NullPtr );
        NANE_ASSERT_RV( m->interface != NULL, "IFile must be valid", NullPtr );
        FileArchive::Implementation* fileArchiveImpl = NULL;
        IFileArchive* fileArchiveInterface = m->interface->CreateArchive(_input.Get());
        if( fileArchiveInterface != NULL )
        {
            fileArchiveImpl = new FileArchive::Implementation(m, fileArchiveInterface);
        }
        return FileArchive(fileArchiveImpl);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
    FileArchive FileArchiveSystem::CreateArchive( const char* _filename )
    {
        NANE_ASSERT_RV( m->interface != NULL, "FileArchiveSystem must be initialized", NullPtr );
        NANE_ASSERT_RV( _filename != NULL, "filename must be valid", NullPtr );
        FileArchive::Implementation* fileArchiveImpl = NULL;
        IFileArchive* fileArchiveInterface = m->interface->CreateArchive(_filename);
        if( fileArchiveInterface != NULL )
        {
            fileArchiveImpl = new FileArchive::Implementation(m, fileArchiveInterface);
        }
        return FileArchive(fileArchiveImpl);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////
}   // namespace nane
